home *** CD-ROM | disk | FTP | other *** search
/ SGI Hot Mix 17 / Hot Mix 17.iso / HM17_SGI / research / lib / modifyct.pro < prev    next >
Text File  |  1997-07-08  |  4KB  |  128 lines

  1. ; $Id: modifyct.pro,v 1.4 1997/01/15 03:11:50 ali Exp $
  2. ;
  3. ; Copyright (c) 1982-1997, Research Systems, Inc.  All rights reserved.
  4. ;       Unauthorized reproduction prohibited.
  5.  
  6. PRO MODIFYCT, ITAB, NAME, R, G, B, FILE=file    ;MODIFY COLOR TABLE IN FILE
  7. ;+
  8. ; NAME:
  9. ;    MODIFYCT 
  10. ;
  11. ; PURPOSE:
  12. ;    Update the distribution color table file "colors1.tbl" or the
  13. ;    user-supplied file with a new table.
  14. ;
  15. ; CATEGORY:
  16. ;    Z4 - Image processing, color table manipulation.
  17. ;
  18. ; CALLING SEQUENCE:
  19. ;    MODIFYCT, Itab, Name, R, G, B
  20. ;
  21. ; INPUTS:
  22. ;    Itab:    The table to be updated, numbered from 0 to 255.  If the
  23. ;        table entry is greater than the next available location
  24. ;        in the table, then the entry will be added to the table
  25. ;        in the available location rather than the index specified
  26. ;        by Itab.  On return, Itab will contain the index for the
  27. ;        location that was modified or extended.  The table 
  28. ;        can be loaded with the IDL command:  LOADCT, Itab.
  29. ;
  30. ;    Name:    A string up to 32 characters long that contains the name for 
  31. ;        the new color table.
  32. ;
  33. ;    R:    A 256-element vector that contains the values for the red
  34. ;        color gun.
  35. ;
  36. ;    G:    A 256-element vector that contains the values for the green
  37. ;        color gun.
  38. ;
  39. ;    B:    A 256-element vector that contains the values for the blue
  40. ;        color gun.
  41. ;
  42. ; KEYWORD PARAMETERS:
  43. ;    FILE:    If this keyword is set, the file by the given name is used
  44. ;        instead of the file colors1.tbl in the IDL directory.  This
  45. ;        allows multiple IDL users to have their own color table file.
  46. ;        The file specified must be a copy of the colors1.tbl file.
  47. ;        The file must exist.
  48. ;
  49. ; OUTPUTS:
  50. ;    Itab:    The index of the entry which was updated, 0 to 255.  This
  51. ;        may be different from the input value of Itab if the
  52. ;        input value was greater than the next available location
  53. ;        in the table.  If this was the case the entry was added to
  54. ;        the table in the next available location instead of leaving
  55. ;        a gap in the table.
  56. ;
  57. ; COMMON BLOCKS:
  58. ;    None.
  59. ;
  60. ; SIDE EFFECTS:
  61. ;    The distribution file "colors.tbl1" or the user-supplied file is
  62. ;    modified with the new table.
  63. ;
  64. ; PROCEDURE:
  65. ;    Straightforward.
  66. ;
  67. ; MODIFICATION HISTORY:
  68. ;    Aug, 1982, DMS, Written.
  69. ;    Unix version, 1987, DMS.
  70. ;    ACY, 9/92, Update for new color table structure, Add FILE keyword.
  71. ;           Allow extending table.
  72. ;    WSO, 1/95, Updated for new directory structure
  73. ;    
  74. ;-
  75.   ON_ERROR,2                    ;Return to caller if an error occurs
  76.   IF (ITAB LT 0)OR(ITAB GT 255) THEN message, $
  77.         'Color table number out of range.'
  78.   
  79.   IF (N_ELEMENTS(file) GT 0) THEN filename = file $
  80.   ELSE filename = FILEPATH('colors1.tbl', subdir=['resource', 'colors'])
  81.  
  82.   GET_LUN,IUNIT        ;GET A LOGICAL UNIT
  83.   OPENU,IUNIT, filename, /BLOCK  ;OPEN FILE
  84.   ntables = 0b
  85.   readu, IUNIT, ntables
  86.  
  87.   if (ITAB LT ntables) then begin    ; Update an existing record
  88.      AA=ASSOC(IUNIT,BYTARR(32,ntables), ntables*768L+1)    ;UPDATE NAME RECORD.
  89.      a = aa[0]
  90.      a[*,ITAB] = 32B            ;blank out old name
  91.      a[0:strlen(name)-1,ITAB] = byte(name)
  92.      aa[0]=a                ;Write names out
  93.  
  94.      AA=ASSOC(IUNIT,BYTARR(256),1)    ;UPDATE VECTORS. SKIP PAST COUNT
  95.      AA[ITAB*3]   = BYTE(R)        ;PUT IN RED. GUARANTEE BYTE
  96.      AA[ITAB*3+1] = BYTE(G)        ;GREEN IN 2ND BLOCK
  97.      AA[ITAB*3+2] = BYTE(B)        ;BLUE IN 3RD BLOCK
  98.  
  99.   endif else begin            ; Add a new record at the end of table
  100.      ITAB = ntables
  101.      ; Add new vectors.  First, read names, then insert vectors
  102.      AA=ASSOC(IUNIT,BYTARR(32,ntables), ntables*768L+1) ;UPDATE NAME RECORD.
  103.      a = aa[0]
  104.      ; Skip past old vectors
  105.      AA=ASSOC(IUNIT,BYTARR(256),ntables*768L+1)      ;UPDATE VECTORS
  106.      AA[0] = BYTE(R)             ;PUT IN RED. GUARANTEE BYTE
  107.      AA[1] = BYTE(G)             ;GREEN IN 2ND BLOCK
  108.      AA[2] = BYTE(B)             ;BLUE IN 3RD BLOCK
  109.  
  110.      ; Skip past new vector to put in names
  111.      AA=ASSOC(IUNIT,BYTARR(32,ntables+1), (ntables+1)*768L+1)
  112.      ; Add new name to end
  113.      temp=bytarr(32)+32B
  114.      temp[0:strlen(name)-1]=byte(name)
  115.      allnames=bytarr(32,ntables+1)
  116.      allnames[*,0:ntables-1] = a
  117.      allnames[*,ntables]=temp
  118.      AA[0] = allnames        ; write the names out
  119.           
  120.      ; Update count
  121.      AA=ASSOC(IUNIT,BYTARR(1))
  122.      AA[0] = [ntables+1B]
  123.   endelse
  124.  
  125.   FREE_LUN,IUNIT
  126.   RETURN
  127. END
  128.